package com.yuxinmuyu.sports_management.controller.publicController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuxinmuyu.sports_management.bean.entiy.SStudent;
import com.yuxinmuyu.sports_management.bean.request.GetSStudentRequest;
import com.yuxinmuyu.sports_management.bean.request.GetSelectStudentRequest;
import com.yuxinmuyu.sports_management.bean.request.StudentIDRequest;
import com.yuxinmuyu.sports_management.bean.request.UpdateStudentRequest;
import com.yuxinmuyu.sports_management.bean.response.sStudentPageResponse;
import com.yuxinmuyu.sports_management.exception.R;
import com.yuxinmuyu.sports_management.service.SStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sStudent")
@Api(value="学生信息",tags = {"学生信息"})
public class SStudentController {
    @Resource
    SStudentService sStuendentService;
    @ApiOperation("分页展示学生信息")
    @PostMapping("/getStudentInfo")
    public R<Page<SStudent>>getStudentInfo(@RequestBody @Validated GetSStudentRequest request){
        return R.success(sStuendentService.getStudentInfo(request));
    }

    @ApiOperation("查询学生信息分页")
    @PostMapping("/adm/sStudent")
    public R<Page<sStudentPageResponse>> selectStudent(@RequestBody @Validated GetSelectStudentRequest request){
        return R.success(sStuendentService.selectStudent(request));
    }

    @ApiOperation("根据学生ID删除学生信息")
    @PostMapping("/adm/deleteStudent")
    public R<?>deleteStudent(@RequestBody @Validated StudentIDRequest request){
        sStuendentService.deleteStudent(request);
        return R.success("删除成功！",null);
    }

    @ApiOperation("根据学生ID获取学生信息")
    @PostMapping("/adm/getStudentByID")
    public R<sStudentPageResponse>getStudentByID(@RequestBody @Validated StudentIDRequest request){
        return R.success(sStuendentService.selectStudentByID(request));
    }
    @ApiOperation("添加学生信息")
    @PostMapping("/adm/addStudent")
    public R<?>addStudent(@RequestBody @Validated SStudent student){
        sStuendentService.addStudent(student);
        return R.success("添加成功!");
    }
    @ApiOperation("修改学生信息")
    @PostMapping("/adm/updateStudent")
    public R<?>updateStudent(@RequestBody @Validated UpdateStudentRequest student){
        sStuendentService.updateStudent(student);
        return R.success("修改成功!");
    }
}
